package org.darkforest.ucenter.service.impl;

import org.apache.commons.codec.digest.DigestUtils;
import org.darkforest.dao.mapper.AlbumPicMapper;
import org.darkforest.dao.mapper.GoodsCommonMapper;
import org.darkforest.dao.mapper.SellerMapper;
import org.darkforest.model.Admin;
import org.darkforest.model.GoodsCommon;
import org.darkforest.model.Seller;
import org.darkforest.ucenter.service.SellerService;
import org.darkforest.vo.StoreSellerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by valentina on 15/4/26.
 */
@Service
public class SellerServiceImpl implements SellerService{
    @Autowired
    private SellerMapper sellerMapper;
    @Autowired
    private GoodsCommonMapper goodsMapper;
    @Autowired
    private AlbumPicMapper picMapper;

    @Override
    public StoreSellerVo sellerLogin(String seller_name, String pwd) {
        StoreSellerVo sellerVo = new StoreSellerVo();
        sellerVo.setSellerName(seller_name);
        sellerVo.setPwd(DigestUtils.md5Hex(pwd));
        StoreSellerVo res = sellerMapper.sellerLogin(sellerVo);
        if(res!=null && res.getStoreState() == 1){
            sellerMapper.updateLastLoginTime(res.getSellerId());
        }
        return res;
    }

    @Override
    public Admin adminLogin(String admin_name, String pwd) {
        return null;
    }

    @Override
    public Integer getGoodsNum(int storeId, int goodsState, int verify) {
        GoodsCommon goods = new GoodsCommon();
        goods.setStoreId(storeId);
        goods.setGoodsState((byte)goodsState);
        goods.setGoodsVerify((byte)verify);
        return goodsMapper.getGoodsNum(goods);
    }

    @Override
    public Integer getPicNum(int storeId) {

        return picMapper.getPicNum(storeId);
    }

    /**
     * 根据条件查询
     *
     * @param seller
     * @return
     */
    @Override
    public List<Seller> findByCondition(Seller seller) {
        return sellerMapper.findSellerByCondition(seller);
    }


}
